<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">商品名称</label>
        <el-input v-model="query.productName" clearable placeholder="商品名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">商品分类</label>
        <el-input v-model="query.categories" clearable placeholder="商品分类" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
        <label class="el-form-item-label">商品已售</label>
        <el-input v-model="query.productSold" clearable placeholder="商品已售" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="550px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="100px">
          <el-form-item label="商品名称">
            <el-input v-model="form.productName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品规格">
            <el-input v-model="form.specifi" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品封面">
            <!--            <el-input v-model="form.produconver" style="width: 370px;" />-->
            <el-upload
              class="upload-demo"
              :action="uploadUrl"
              list-type="picture"
              multiple
              drag
            >
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,只需上传一张即可，且不超过500kb</div>
            </el-upload>
          </el-form-item>
          <el-form-item label="商品轮播图">
            <!--            <el-input v-model="form.commcarousel" style="width: 370px;" />-->
            <el-upload
              class="upload-demo"
              :action="uploadUrlcommdits"
              list-type="picture"
              multiple
              drag
            >
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">上传jpg/png文件，且不超过500kb</div>
            </el-upload>
          </el-form-item>
          <el-form-item label="商品分类">
            <!--            <el-input v-model="form.categories" style="width: 370px;" />-->
            <el-select v-model="form.categories" filterable class="edit-input" clearable size="mini" placeholder="请选择">
              <el-option
                label="厨卫"
                value="厨卫"
              />
              <el-option
                label="食品"
                value="食品"
              />
              <el-option
                label="洗护"
                value="洗护"
              />
              <el-option
                label="居家"
                value="居家"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="商品详情">
            <el-input v-model="form.produdetails" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品状态">
            <el-radio-group v-model="form.status" style="width: 300px">
              <el-radio label="下架">下架</el-radio>
              <el-radio label="上架">上架</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="商品价格">
            <el-input v-model="form.price" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="运费">
            <el-input v-model="form.freigh" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="库存">
            <el-input v-model="form.insock" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所需兑换积分">
            <el-input v-model="form.pintsRedeem" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品已售">
            <el-input v-model="form.productSold" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品详情图">
            <!--            <el-input v-model="form.detailsMap" style="width: 370px;" />-->
            <el-upload
              class="upload-demo"
              :action="uploaddetails"
              list-type="picture"
              multiple
              drag
            >
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">上传jpg/png多个文件文件，且不超过500kb</div>
            </el-upload>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="productName" label="商品名称" />
        <el-table-column prop="specifi" label="商品规格" />
        <el-table-column prop="produconver" label="商品封面" />
        <el-table-column prop="categories" label="商品分类" />
        <el-table-column prop="produdetails" label="商品详情" />
        <el-table-column prop="status" label="商品状态" />
        <el-table-column prop="price" label="商品价格" />
        <el-table-column prop="freigh" label="运费" />
        <el-table-column prop="insock" label="库存" />
        <el-table-column prop="productSold" label="商品已售" />
        <el-table-column v-if="checkPer(['admin','commodityManage:edit','commodityManage:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudCommodityManage from '@/api/system/commodityManage'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, productName: null, specifi: null, produconver: null, commcarousel: null, categories: null, keyworlds: null, produdetails: null, status: null, price: null, freigh: null, insock: null, pintsRedeem: null, detailsMap: null, productSold: 0 }
export default {
  name: 'CommodityManage',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: 'api/commdit', url: 'api/commodityManage', idField: 'id', sort: 'id,desc', crudMethod: { ...crudCommodityManage }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'commodityManage:add'],
        edit: ['admin', 'commodityManage:edit'],
        del: ['admin', 'commodityManage:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'productName', display_name: '商品名称' },
        { key: 'categories', display_name: '商品分类' },
        { key: 'productSold', display_name: '商品已售' }
      ],
      // http://106.15.74.249,http://localhost:8083
      uploadUrlcommdits: 'http://106.15.74.249/api/uploadcommdity',
      uploadUrl: 'http://106.15.74.249/api/upload',
      uploaddetails: 'http://106.15.74.249/api/uploaddetails',
      // 定义图片网络访问地址
      imageUrlPath: '',
      // 定义图片控制开关
      dialogImageVisible: false
    }
  },
  methods: {
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
